import requests

from 接口自动化.电子商城实战.apis.base_api import BaseApi


class Goods(BaseApi):
    def create_goods(self, add_data):
        url = "/admin/goods/create"
        r = self.send_req("POST", url, json=add_data)
        return r

    def goods_list(self, goods_name, order="desc", sort="add time"):
        good_list_url = "/admin/goods/list"
        data = {"name": goods_name, "order": order, "sort": sort}
        r = self.send_req("GET", good_list_url, json=data)
        return r

    def goods_detail(self, goods_id):
        goods_detail_url = "/admin/goods/detail"
        param = {
            "id": goods_id
        }
        r = self.send_req("GET", goods_detail_url, params=param)
        return r

    def del_goods(self, goods_id):
        del_url = "admin/goods/delete"
        del_data = {
            "id": goods_id
        }
        r = self.send_req("POST", del_url, json=del_data)
        return r
